n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
SUM = 0
for i in range(n):
    for j in range(m):
        SUM += a[i][j]

ans = []        
for i1 in range(1, n - 1):
    for i2 in range(i1, n - 1):
        for j1 in range(1, m - 1):
            for j2 in range(j1, m - 1):
                SUM1 = 0
                for i in range(i1):
                    for j in range(j1):
                        SUM1 += a[i][j]
                SUM2 = 0        
                for i in range(i1):
                    for j in range(j2 + 1, m):
                        SUM2 += a[i][j]
                SUM3 = 0
                for i in range(i2 + 1, n):
                    for j in range(j1):
                        SUM3 += a[i][j]
                SUM4 = 0
                for i in range(i2 + 1, n):
                    for j in range(j2 + 1, m):
                        SUM4 += a[i][j]  

                sum_x = SUM - SUM1 - SUM2 - SUM3 - SUM4
                ans.append(sum_x)
print(max(ans))
